import axios from 'axios'
// import { message as Msg } from 'ant-design-vue'
import useToken from '../stores/token.js'
const serive = axios.create({
  baseURL: '/api',
  timeout: 10000
})

//请求拦截器
serive.interceptors.request.use(
  (config) => {
    const { token } = useToken()
    if (token) {
      config.headers.Authorization = `${token}`
    }
    // console.log('请求成功' + config)
    return config
  },
  (error) => Promise.reject(error)
)

//响应拦截器
serive.interceptors.response.use(
  (response) => {

    const {data} = response
    // console.log('响应成功' + response)
    // console.log('响应成功' + response)
    console.log('响应成功' + response)
    return data
  },
  (error) => {
    // console.log('响应错误' + error)
    // Msg.success(error.response.data.msg)
    return Promise.reject(error)
  }
)
export default serive
